package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.Building;
import com.example.mybatisplus.mapper.BuildingMapper;
import com.example.mybatisplus.model.domain.Dot;
import com.example.mybatisplus.service.BuildingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzy
 * @since 2024-06-24
 */
@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements BuildingService {
    @Autowired
    private BuildingMapper buildingMapper;
    public List<Building> selectBuildByNamePage(String name, Dot dot){
        Page<Building> buildingPage = new Page<>(dot.getPageNo(), dot.getPageSize());
        QueryWrapper<Building> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0).like("name", name);
        IPage<Building> buildingIPage = buildingMapper.selectPage(buildingPage, wrapper);
        return buildingIPage.getRecords();
    }

    public int getTotelByBuildingID(Long BuildingID) {
        int id = buildingMapper.getTotelByBuildingID(BuildingID);
        return id;
    }


    public List<Building> selectBuildByGenderPage( Dot dot) {
        Page<Building> buildingPage = new Page<>(dot.getPageNo(), dot.getPageSize());
        QueryWrapper<Building> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0).eq("type", dot.getData());
        IPage<Building> buildingIPage = buildingMapper.selectPage(buildingPage, wrapper);
        return buildingIPage.getRecords();
    }
    public List<Building> selectBuildByAreaPage( Dot dot) {
        Page<Building> buildingPage = new Page<>(dot.getPageNo(), dot.getPageSize());
        QueryWrapper<Building> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0).eq("area", dot.getData());
        IPage<Building> buildingIPage = buildingMapper.selectPage(buildingPage, wrapper);
        return buildingIPage.getRecords();
    }



    public boolean buildingModify(Building building) {
        QueryWrapper<Building> wrapper = new QueryWrapper<Building>()
                .eq("ID",building.getId())
                .eq("is_deleted", building.getIsDeleted());
        Building building1 = buildingMapper.selectOne(wrapper);
        if(building1!=null){
            buildingMapper.updateById(building);
            return true;
        }
        return false;

    }

    @Override
    public List<Building> selectBuildingsByDormitoryAdminIDs(List<Long> ids) {
        return buildingMapper.selectBuildingsByDormitoryAdminIDs(ids);
    }

    @Override
    public List<Map<String, Object>> selectBuildingWithAreaNameByBuildingName(Dot dot) {

        return buildingMapper.selectBuildingWithAreaNameByBuildingName(dot);
    }

    @Override
    public List<Building> selectBuildingByAreaID(Long areaID) {

        return buildingMapper.selectBuildingByAreaID(areaID);
    }


}
